package kitrobot.com.bed.fragment;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

import kitrobot.com.wechat_bottom_navigation.R;

public class ListViewAdapter extends BaseAdapter {

    private List<Map<String, Object>> data;
    private LayoutInflater layoutInflater;
    private Context context;
    public ListViewAdapter(Context context,List<Map<String, Object>> data){
        this.context=context;
        this.data=data;
        this.layoutInflater=LayoutInflater.from(context);
    }
    /**
     * 组件集合，对应list.xml中的控件
     * @author Administrator
     */
    public final class Person{
        public TextView tel;
        public TextView names;
        public TextView times;
    }
    @Override
    public int getCount() {
        return data.size();
    }
    /**
     * 获得某一位置的数据
     */
    @Override
    public Object getItem(int position) {
        return data.get(position);
    }
    /**
     * 获得唯一标识
     */
    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Person person=null;
        if(convertView==null){
            person=new Person();
            //获得组件，实例化组件
            convertView=layoutInflater.inflate(R.layout.listview_person, null);
            person.tel= (TextView) convertView.findViewById(R.id.tv_lit);
            person.names=(TextView)convertView.findViewById(R.id.tv_lin);
            person.times=(TextView)convertView.findViewById(R.id.tv_litm);
            convertView.setTag(person);
        }else{
            person=(Person)convertView.getTag();
        }
        //绑定数据
        person.tel.setText((String)data.get(position).get("tel"));
        person.names.setText((String)data.get(position).get("names"));
        person.times.setText((String)data.get(position).get("times"));

        return convertView;
    }

}